<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	<h4 class="modal-title">选择模板</h4>
</div>
<div class="modal-body">
	<div class="row">
		<div class="col-lg-4">
			<div id="fileTreeView"></div>
		</div>
		<div class="col-lg-8">
			<table id="fileListTable" class="table table-striped table-hover">
				<thead>
					<tr>
						<th width="60">#</th>
						<th>名称</th>
						<th>类型</th>
						<th>大小</th>
						<th>操作</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
</div>
<div class="modal-footer">
	<button class="btn btn-primary" type="button" id="selectOkBtn">
		<strong>确 定</strong>
	</button>
	<button type="button" class="btn btn-default" data-dismiss="modal">
		<strong>关 闭</strong>
	</button>
</div>
<script th:inline="javascript">
    /*<![CDATA[*/
    //表格
    var fileListTable;
    //表格列定义
    var columnDefs2 = [ {
        //第一列，用来拖拽
        "searchable" : false,
        "orderable" : false,
        "targets" : 0
    } ];
    var columns2 = [ {
        //第一列，用来拖拽
        "data" : null,
        "class" : "text-center",
        render : function(data, type, row, meta) {
            return '<label><input type="radio" value="'+row.filePath+'" name="optionsRadios" /></label>';
        }
    }, {
        "data" : "fileName",
        render : function(data, type, row, meta) {
            var fileClass = row.leaf ? 'fa fa-file-code-o text-warning' : 'fa fa-folder text-warning';
            if (!row.leaf) {
                return '<a href="#"><i class="'+fileClass+'"></i> ' + data + '</a>';
            } else {
                return '<a href="#"><i class="'+fileClass+'"></i> ' + data + '</a>';
            }
        }
    }, {
        "data" : "format"
    }, {
        "data" : "fileLength",
        render : function(data, type, row, meta) {
            return TG_UTIL.fileSize(data);
        }
    }, {
        "data" : null, //最后一列，操作按钮
        "class" : "text-center",
        render : function(data, type, row, meta) {
            var result = '';
            //删除按钮
            result += ' <a href="#" type="button" onclick="deleteFile(this)" filePath="' + row.filePath + '" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a>';
            return result;
        }
    } ];

    var parentPath = '';
    //ajax参数
    var ajaxDataParamFun2 = function(d) {
        d.parentPath = parentPath;
    };
    //表格setting
    var setting2 = {
        listUrl : /*[[@{/admin/m/base/template/getTemplatesByPath.gsp}]]*/'url',
        columnDefs : columnDefs2, //表格列定义
        columns : columns2, //表格列
        dataTableDiv : 'fileListTable', //表格
        ajaxDataParamFun : ajaxDataParamFun2, //ajax参数
        pageable : false, //是否分页
        showIndexColumn : false, //是否显示第一列的索引列
        enabledChange : false
    };
    //创建表格
    fileListTable = new TG_Tabel.createNew(setting2);
    //加载完成后执行
    $(function() {
        //表格初始化
        fileListTable.init();

        var url = /*[[@{/admin/m/base/template/getFileTree.gsp}]]*/'url';
        tg_simpleAjaxPost(url, {
            codeNum : ''
        }, function(d) {
            var result = $.parseJSON(d);
            $('#fileTreeView').treeview({
                color : "#428bca",
                showBorder : false,
                nodeIcon : null,
                data : result.obj.nodes,
                onNodeSelected : function(event, folder) {
                    parentPath = folder.filePath;
                    fileListTable.refresh();
                }
            });
        });
    });

    function refreshFileList(obj) {
        if ($(obj).attr('leaf') == 'false') {
            parentPath = $(obj).attr('parentPath');
            fileListTable.refresh();
        }
    }

    $('#selectOkBtn').click(function() {
        var selVal = $('#fileListTable input[name="optionsRadios"]:checked').val();
        var fileName = /*[[${fileName}]]*/'';
        $('form input[name="' + fileName + '"]').val(selVal);
        $('#selectTemplateWin').modal("hide");
    });
    /*]]>*/
</script>
